package yjxxgl.action;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import net.sf.json.JSONArray;
import yjxxgl.agent.JsyjAgent;
import common.BaseClasses.CommonAction;
import common.BaseClasses.util.IocUtil;

public class JsyjAction extends CommonAction{

	private JsyjAgent jsyjAgent;
	
	public JsyjAction(){
		try {
			this.jsyjAgent=(JsyjAgent) IocUtil.getIocImpl("yjxxgl/ioc/ioc-jsyj.xml","jsyjAgent");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	private void init() throws Throwable {
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		response.setContentType("text/html; charset=UTF-8");
	}

	
	public void findDbWaterYJInfo(){
		try {
			init();
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
			System.out.println(df.format(new Date()));
			String date=df.format(new Date());
			/*List list=jsyjAgent.findByTime("2014/3/11 22:00:00");*/
			List list=jsyjAgent.findByTime(date);
			System.out.println(list);
			PrintWriter out = response.getWriter();
			JSONArray js = JSONArray.fromObject(list);
			out.print(js);
			out.flush();
			out.close();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//查询水位
	public void findSw(){
			try {
				init();
				String startTime=request.getParameter("startTime");
				String endTime=request.getParameter("endTime");
				String cezhanNM=request.getParameter("cezhanNM");
				List list=jsyjAgent.findSW(startTime, endTime, cezhanNM);
				System.out.println(list);
				PrintWriter out = response.getWriter();
				JSONArray js = JSONArray.fromObject(list);
				out.print(js);
				out.flush();
				out.close();
				
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
	//查询流量
	public void findLl(){
		try {
			init();
			String startTime=request.getParameter("startTime");
			String endTime=request.getParameter("endTime");
			String cezhanNM=request.getParameter("cezhanNM");
			List list=jsyjAgent.findLl(startTime, endTime, cezhanNM);
			System.out.println(list);
			PrintWriter out = response.getWriter();
			JSONArray js = JSONArray.fromObject(list);
			out.print(js);
			out.flush();
			out.close();
			
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
}

	public JsyjAgent getJsyjAgent() {
		return jsyjAgent;
	}

	public void setJsyjAgent(JsyjAgent jsyjAgent) {
		this.jsyjAgent = jsyjAgent;
	}
	
}
